﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace UI.View.Feiyong
{
    /// <summary>
    /// WuyeFei.xaml 的交互逻辑
    /// </summary>
    public partial class WuyeFei : Page
    {

        ViewModel.WuyeViewModel vm;
        public WuyeFei()
        {
            InitializeComponent();

            vm = DataContext as ViewModel.WuyeViewModel;
            LoadData();
        }


        Model.DataContext context = new Model.DataContext();
        public void LoadData()
        {
             vm.ListFeeBill = context.DB.Queryable<Model.PmFeeBill>().ToList();
        }

 

        private void Btn_JiaoFei_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (vm.CurrFeeBill!=null)
                {
                    context.DB.Deleteable<Model.PmFeeBill>(vm.CurrFeeBill).ExecuteCommand();
                    HandyControl.Controls.Growl.SuccessGlobal("作废成功！");
                    LoadData();
                }
                else
                {
                    HandyControl.Controls.Growl.WarningGlobal("请选择收费单！");
                }

            }
            catch (Exception ex)
            {

                HandyControl.Controls.Growl.FatalGlobal(ex.Message);
            }



        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            
        }

        private void Btn_Add_Click(object sender, RoutedEventArgs e)
        {
           
          vm.Dialog =  HandyControl.Controls.Dialog.Show(new View.Feiyong.Part.PmPay());
        }

        private async void Btn_Query_Click(object sender, RoutedEventArgs e)
        {
            var id = cmb_BillId.Text;
            var No = txt_roomNo.Text;
            var name = txt_OwnerName.Text;
            var query = context.DB.Queryable<Model.PmFeeBill>();
            if (!string.IsNullOrEmpty(id))
            {
                query = query.Where(r => r.Id.ToString() == id);
            }

            if (!string.IsNullOrEmpty(No))
            {
                query = query.Where(b => b.RoomNo == No);
            }
            if (!string.IsNullOrEmpty(name))
            {
                query = query.Where(b => b.UserName.Contains( Name));
            }



            vm.ListFeeBill = await query.ToListAsync();
        }
    }
}
